﻿using Autofac;
using System;

namespace Moon.Sql.Test
{
    class Program
    {
        static void Main(string[] args)
        {
            MySqlTest();
            SqlServerTest();
            OracleTest();
            RepositoryTest();
            //InjectionTest();
            Console.WriteLine("== over ==");
            Console.ReadKey();
        }

        static void SqlServerTest()
        {
            SqlServerTest sql = new SqlServerTest();
            //sql.BulkInsertTest();
            //sql.InsertTest();
            //sql.UpdateTest();
            //sql.DeleteTest();
            //sql.BatchTest();
            //sql.ProcTest();
            //sql.TransactionTest();
            //sql.QueryTest();
            //sql.DbTest();
            //sql.LambdaQueryTest();
            //sql.DbFirstTest();
        }

        static void MySqlTest()
        {
            MySqlTest sql = new MySqlTest();
            //sql.BulkInsertTest();
            //sql.InsertTest();
            //sql.UpdateTest();
            //sql.DeleteTest();
            //sql.BatchTest();
            //sql.ProcTest();
            //sql.TransactionTest();
            //sql.QueryTest();
            //sql.DbTest();
            //sql.ThreadTest();
            //sql.LambdaQueryTest();
            //sql.DbFirstTest();
        }

        static void OracleTest()
        {
            OracleTest sql = new OracleTest();
            //sql.InsertTest();
            //sql.BulkInsertTest();
            //sql.UpdateTest();
            //sql.DeleteTest();
            //sql.BatchTest();
            //sql.ProcTest();
            //sql.TransactionTest();
            //sql.QueryTest();
            //sql.DbTest();
            //sql.LambdaQueryTest();
            //sql.DbFirstTest();
        }

        static void RepositoryTest()
        {
            Moon.Sql.Test.RepositoryTest repositoryTest = new Moon.Sql.Test.RepositoryTest();
            //repositoryTest.Test();
        }

        static void InjectionTest()
        {
            var builder = new ContainerBuilder();
            builder.Register(c =>
            {
                IMoonSql msql = new MoonSql(Moon.Sql.Test.MySqlTest.connectionString, DatabaseType.MySql);
                msql.OnExecuted = (e) => { };
                msql.OnExecuting = (e) =>
                {
                    Console.WriteLine(e.Sql);
                    Console.WriteLine(e.ParametersString);
                };
                return msql;
            }).As<IMoonSql>().SingleInstance();

            builder.Register(c =>
            {
                IMoonSql<MySqlDb> msql = new MoonSql<MySqlDb>(Moon.Sql.Test.MySqlTest.connectionString, DatabaseType.MySql);
                msql.OnExecuted = (e) => { };
                msql.OnExecuting = (e) =>
                {
                    Console.WriteLine(e.Sql);
                    Console.WriteLine(e.ParametersString);
                };
                return msql;
            }).As<IMoonSql<MySqlDb>>().SingleInstance();

            builder.Register(c =>
            {
                IMoonSql<SqlServerDb> msql = new MoonSql<SqlServerDb>(Moon.Sql.Test.SqlServerTest.connectionString, DatabaseType.SqlServer);
                msql.OnExecuted = (e) => { };
                msql.OnExecuting = (e) =>
                {
                    Console.WriteLine(e.Sql);
                    Console.WriteLine(e.ParametersString);
                };
                return msql;
            }).As<IMoonSql<SqlServerDb>>().SingleInstance();

            builder.RegisterType<InjectionTest>().As<IInjectionTest>();

            var container = builder.Build();
            var instance = container.Resolve<IInjectionTest>();
            instance.Test();
        }
    }
}
